package ru.kreda.webapp.client.data;

import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.LoadListener;
import com.extjs.gxt.ui.client.store.ListStore;

public class CustomListStore<M extends ModelData> extends ListStore<M> {

	private LoadListener loadListener = new LoadListener() {

		public void loaderBeforeLoad(LoadEvent le) {
			onBeforeLoad(le);
		}

		public void loaderLoad(LoadEvent le) {
			onLoad(le);
		}

		public void loaderLoadException(LoadEvent le) {
			onLoadException(le);
		}

	};

	@SuppressWarnings("unchecked")
	public void bind(ListLoader<? extends ListLoadResult<M>> loader) {
		if (this.loader != null) {
			this.loader.removeLoadListener(loadListener);
		}
		this.loader = (ListLoader<ListLoadResult<M>>) loader;
		this.loader.addLoadListener(loadListener);
	}

}
